home *** CD-ROM | disk | FTP | other *** search
/ VRML Browsing & Building Cyberspace / VRML - Browsing and Building Cyberspace.iso / examples / orrey.pl < prev    next >
Perl Script  |  1995-06-30  |  2KB  |  67 lines

  1. #!/usr/bin/perl
  2. #
  3. # Sample Orrey program in PERL
  4. # Written by Mark Pesce, June 1995
  5. # No rights reserved.
  6. #
  7. # Let's do some time math.
  8. #
  9. # Get seconds since start of 1995.
  10. # First get seconds as of 1 Jan 1995
  11. # We cheated and precalculated this number.
  12. # We cheated and got the number of seconds in a year, as well.
  13. # Oh, alright, we did it for the seconds in a lunar month, too!
  14. #
  15. $yearZero = 788918400;
  16. $secInYear = 31557600; 
  17. $secInLuMonth = 2514360;
  18. $rightNow = time();
  19. $sinceZero = $rightNow - $yearZero;
  20. #print "There have been ", $sinceZero, " seconds since New Year GMT.\n";
  21. $theSpin = ($sinceZero / $secInYear) * (3.1416 * 2);
  22. #print "We are ", $theSpin, " through the year.\n";
  23. #
  24. # So now calculate x SIN and y COS values for Earth's position around the Sun
  25. # The value of 20 is preserved from the original Translation node
  26. #
  27. $xVal = 20 * sin($theSpin);
  28. $zVal = 20 * cos($theSpin); 
  29. #
  30. $laLune = ($sinceZero / $secInLuMonth) * (3.1416 * 2);
  31. $xMoon = 4 * sin($laLune);
  32. $yMoon = 4 * cos($laLune);
  33. #
  34. # Always send the content type before everything else
  35. #
  36. print "Content-type: x-world/x-vrml\n\n";
  37. #
  38. # Then send the file header
  39. #
  40. print "#VRML V1.0 ascii\n";
  41. #
  42. # First, define the Sun.
  43. #
  44. print "Separator { Material { emissiveColor 1 1 0 } PointLight { intensity 1 color 1 1 0.9 } \n";
  45. print "Sphere { radius 10 }\n";
  46. #
  47. # Next, the Earth.
  48. print "Separator {\n";
  49. print "Transform { translation ";
  50. printf "%g %g 0 }\n", $xVal, $zVal;
  51. print "Material { diffuseColor 0 0 1 specularColor 0.9 0.9 0.9 shininess 0.9 }\n";
  52. print "Texture2 { filename \"http://hyperreal.com/~mpesce/WORLDMAP.RGB\"  } Sphere { radius 2 }\n";
  53. #
  54. # Finally, the Moon.
  55. #
  56. print "Separator {\n";
  57. print "Transform { translation ";
  58. printf "%g %g 0 }\n", $xMoon, $yMoon;
  59. print "Material { diffuseColor 0.7 0.7 0.7 shininess 0.3 } Texture2 { image 4 4 3\n";
  60. print "0xC0C0C0 0x808080 0xFFFFFF 0x404040 0x808080 0x202020 0x808080 0xC0C0C0\n";
  61. print "0x202020 0x808080 0xFFFFFF 0x808080 0x808080 0xC0C0C0 0x808080 0x202020 }\n";
  62. print "Sphere { radius 1 } } } }\n";
  63. #  All done.
  64. #
  65.